package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.service.ISysAttributeDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;



@RestController
@RequestMapping("/system/attribute/data")
public class SysAttributeDataController extends BaseController
{


    @Autowired
    private ISysAttributeDataService sysAttributeDataService;
    /**
     * Fetch children names by parentId
     */
//    @PreAuthorize("@ss.hasPermi('system:dept:list')")
//    @GetMapping("/fetchAttributeList")
//    public AjaxResult fetchAttributeList(@RequestParam String parentId) {
//        List<String> names = sysAttributeDataService.fetchAttributeList(parentId);
//        return AjaxResult.success(names);
//    }

    @GetMapping("/fetchAttributeList")
    public AjaxResult fetchAttributeList() {
        List<List<String>> childrenDetails = sysAttributeDataService.fetchAttributeList();
        return AjaxResult.success(childrenDetails);
    }


    @PostMapping("/create")
    public AjaxResult createAttribute(@RequestParam String name,
                                      @RequestParam String description,
                                      @RequestParam String nameEn,
                                      @RequestParam String descriptionEn,
                                      @RequestParam String type) {
        Object result = sysAttributeDataService.createAttribute(name, description, nameEn, descriptionEn, type);
        return AjaxResult.success(result);
    }

    @PostMapping("/delete")
    public AjaxResult deleteAttribute(@RequestParam String id) {
        Object result = sysAttributeDataService.deleteAttribute(id);
        return AjaxResult.success(result);
    }


    @PostMapping("/update")
    public AjaxResult updateAttribute(@RequestParam String id,
                                      @RequestParam String description,
                                      @RequestParam String descriptionEn) {
        Object result = sysAttributeDataService.updateAttribute(id, description, descriptionEn);
        return AjaxResult.success(result);
    }

    /**
     * Search attributes by name
     * @param searchString The string to search for in attribute names
     * @return A list of attributes that match the search criteria
     */
    @PostMapping("/search")
    public AjaxResult searchAttribute(@RequestParam String searchString) {
        List<List<String>> result = sysAttributeDataService.searchAttribute(searchString);
        return AjaxResult.success(result);
    }
}
